import axios from 'axios';


let base = 'http://127.0.0.1:8888';

export const requestLogin = params => { return axios.post(`${base}/login/account`, params).then(res => res.data) };


export const getDepartmentListPage = params => { return axios.post(`${base}/department/list`, params ); };

export const removeDepartment = params => { return axios.delete(`${base}/department/`+params); };

export const batchRemoveDepartment = params => { return axios.patch(`${base}/department/`, params ); };

export const editDepartment = params => { return axios.post(`${base}/department`,params ); };

export const getAllManger = () => { return axios.get(`${base}/employee/all` ); };

export const getDepartTree = () => { return axios.get(`${base}/department/deptTree` ); };


export const getEmployeeListPage = params => { return axios.post(`${base}/employee/list`, params ); };

export const removeEmployee = params => { return axios.delete(`${base}/employee/`+params); };

export const batchRemoveEmployee = params => { return axios.patch(`${base}/employee/`, params ); };

export const editEmployee = params => { return axios.post(`${base}/employee`,params ); };

export const getALLShopNoMan = () => { return axios.get(`${base}/shop/all` ); };

// export const getDepartTree = () => { return axios.get(`${base}/employee/deptTree` ); };

export const getShopListPage = params => { return axios.post(`${base}/shop/list`, params ); };

export const removeShop = params => { return axios.delete(`${base}/shop/`+params); };

export const batchRemoveShop = params => { return axios.patch(`${base}/shop/`, params ); };

export const editShop = params => { return axios.post(`${base}/shop`,params ); };



export const getSystemDictionaryDetailListPage = params => { return axios.post(`${base}/dictionaryDetail/list`, params ); };

export const removeSystemDictionaryDetail = params => { return axios.delete(`${base}/dictionaryDetail/`+params); };

export const batchRemoveSystemDictionaryDetail = params => { return axios.patch(`${base}/dictionaryDetail/`, params ); };

export const editSystemDictionaryDetail = params => { return axios.post(`${base}/dictionaryDetail`,params ); };

export const getSystemDictionaryTypeListPage = params => { return axios.post(`${base}/dictionaryType/list`, params ); };

export const removeSystemDictionaryType = params => { return axios.delete(`${base}/dictionaryType/`+params); };

export const batchRemoveSystemDictionaryType = params => { return axios.patch(`${base}/dictionaryType/`, params ); };

export const editSystemDictionaryType = params => { return axios.post(`${base}/dictionaryType`,params ); };

export const getAllSystemDictionaryTypes = () => {return axios.get(`${base}/dictionaryType/all`)};

export const getAllSystemDictionaryDetails = (params) => {return axios.get(`${base}/dictionaryType/detail/`+params)};

export const shopSettlement = params => {return axios.post(`${base}/shop/settlement`,params )};


export const shopLogoDelete = params => {return axios.delete(`${base}/fastDfs?path=`+params )};

export const getSystemPetMsgPendingListPage = params => { return axios.post(`${base}/searchMasterMsg/pending`, params ); };


/*===============================================  宠物Pet相关请求  ===========================================================*/

/** 提交宠物领养的信息*/
export const petMsgNoticeSumbit = params => { return axios.put(`${base}/searchMasterMsg/handle`, params ); };

/** 宠物上架*/
export const petOnSale = params => { return axios.post(`${base}/pet/onsale`, params ); };

/** 获取到所有的宠物类型*/
export const getPetType = () => {return axios.get(`${base}/petType`)};

/** 修改宠物信息 */
export const petEdit = params => { return axios.put(`${base}/pet`,params)};

/** 获取宠物详情*/
export const getPetDetail = params => {return axios.get(`${base}/pet/detail/`+ params)}

/** 根据id批量删除*/
export const batchRemovePet = params => {return axios.patch(`${base}/pet`, params)};

export const getSystemPetMsgProcessedListPage = params => { return axios.post(`${base}/searchMasterMsg/processed`, params ); };

/** 根据id删除 */
export const petDeleteById = params => {return axios.delete(`${base}/pet/` + params )};

/** 添加宠物*/
export const getPetListByConditon = params => {return axios.post(`${base}/pet/list`, params)}

/** 宠物下架*/
export const petOffSale = params => {return axios.post(`${base}/pet/offsale`, params)};

/*===============================================  User管理相关请求  ===========================================================*/

/** 全部所有用户列表 */
export const getUserListPage = params => { return axios.post(`${base}/user/list`, params ); };

export const editUserStatus = params => { return axios.put(`${base}/user`, params ); };


/** 删除用户 */
// export const removeUser = params => { return axios.delete(`${base}/user/`+params); };

/** 批量删除用户 */
// export const batchRemoveUser = params => { return axios.patch(`${base}/user/`, params ); };

/** 修改用户*/
// export const editUser = params => { return axios.post(`${base}/user`,params ); };

/*===============================================  WxUser管理相关请求  ===========================================================*/

/** 全部所有用户列表 */
export const getWxUserListPage = params => { return axios.post(`${base}/wxUser/list`, params ); };

/*===============================================  订单模块相关请求  ===========================================================*/

export const getAdoptOrderList = params => {return axios.post(`${base}/adoptOrder/admin`, params );};

/*===============================================  宠物服务模块相关请求  ===========================================================*/
/** 提交宠物领养的信息*/
export const productMsgNoticeSumbit = params => { return axios.put(`${base}/searchMasterMsg/handle`, params ); };

/** 宠物上架*/
export const productOnSale = params => { return axios.post(`${base}/product/onsale`, params ); };

/** 获取到所有的宠物类型*/
export const getProductType = () => {return axios.get(`${base}/productType`)};

/** 修改宠物信息 */
export const productEdit = params => { return axios.put(`${base}/product`,params)};

/** 获取宠物详情*/
export const getProductDetail = params => {return axios.get(`${base}/product/detail/`+ params)}

/** 根据id批量删除*/
export const batchRemoveProduct = params => {return axios.patch(`${base}/product`, params)};

export const getSystemProductMsgProcessedListPage = params => { return axios.post(`${base}/searchMasterMsg/processed`, params ); };

/** 根据id删除 */
export const productDeleteById = params => {return axios.delete(`${base}/product/` + params )};

/** 添加宠物*/
export const getProductListByConditon = params => {return axios.post(`${base}/product/list`, params)}

/** 宠物下架*/
export const productOffSale = params => {return axios.post(`${base}/product/offsale`, params)};




//======================axios的前置拦截器====================//
//每次路由请求之前：将token设置到请求头 -  token携带到后端
axios.interceptors.request.use(res=>{
    let token = localStorage.getItem("token");
    if(token){
        res.headers["token"] = token;
    }
    return res;
},error => {
    Promise.reject(error)
});

// 获取来自后端的相应，判断此时响应是否有 信息表示没有登陆
axios.interceptors.response.use(res => {
    let data = res.data;
    if (data.msg === "noLogin") {
        this.$router.push("/login")
    }
    return res;
}, error => {
    Promise.reject(error);
})

